package org.meb.conquest.web.ctrl;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import lombok.Getter;
import lombok.Setter;

import org.meb.conquest.db.dao.Query;
import org.meb.conquest.db.model.Deck;
import org.meb.conquest.db.model.User;
import org.meb.conquest.web.auth.TwitterAuthServlet;
import org.meb.conquest.web.auth.WebUser;
import org.meb.conquest.web.services.CardService;
import org.meb.conquest.web.services.DeckService;
import org.meb.conquest.web.services.SearchService;
import org.omnifaces.util.Faces;

@Named
@ViewScoped
@Getter
@Setter
public class DeckViewCtrl implements Serializable {

	private static final long serialVersionUID = -4308071997837944252L;

	@Inject
	private SearchService searchService;

	@Inject
	private CardService cardService;

	@Inject
	private DeckService deckService;
	
	@Inject
	private WebUser webUser;

	private Long deckId;
	private Deck deck;

	@PostConstruct
	public void initialize() {
		deck = null;
	}
	
	public void initViewDeck() {
//		User user = Faces.getSessionAttribute(TwitterAuthServlet.SIGNED_IN_USER);
		
		if (webUser.isNotSignedIn()) {
			throw new IllegalStateException("Not signed in");
		}

		deck = new Deck();
		deck.setUserId(webUser.getUserId());
		deck.setId(deckId);
		Query<Deck> query = new Query<Deck>(deck);
		deck = searchService.findUnique(query);
	}
}
